package testing;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class TimeFormatter {
	
	private GregorianCalendar cal;
	private String date;
	private int year;
	private int month;
	private int day;
	private int hourOfDay;
	private int minute;
	
	public static void main (String args[]){
		String yay = "11/22-2012,10:30";
		TimeFormatter hey = new TimeFormatter(yay);
	}
	
	public TimeFormatter(String time){
		this.date = time;
		this.setGregorian(date);
	}
	
	public Timestamp getTimeStamp()
		{
		return new Timestamp(cal.getTimeInMillis());
		}
	
	public long getTimeInMillis()
		{
		return cal.getTimeInMillis();
		}
	
	public void setGregorian(String time) {
		this.date = time;
		this.cal = new GregorianCalendar();
		this.setYear(date);
		this.setMonth(date);
		this.setDay(date);
		this.setHourOfDay(date);
		this.setMinute(date);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		cal.set(this.getYear(), this.getMonth(), this.getDay(), this.getHourOfDay(), this.getMinute());
		//System.out.println("aha!");
	}
	
	public GregorianCalendar getGregorian(){
		return cal;
	}
	
	public void setYear(String s){
		int index = s.indexOf('-');
		int tempYear = Integer.parseInt("" + s.charAt(index+1) + s.charAt(index+2) + s.charAt(index+3) + s.charAt(index+4));
		this.year = tempYear;
		//System.out.println(this.year);
	}
	
	public int getYear() {
		return year;
	}
	
	public void setMonth(String s){
		int index = s.indexOf('/');
		int tempMonth = Integer.parseInt("" + s.charAt(index+1) + s.charAt(index+2));
		this.month = tempMonth;
		//System.out.println(this.month);
	}
	
	public int getMonth() {
		return month;
	}
	
	public void setDay(String s){
		int index = s.indexOf('/');
		int tempDay = Integer.parseInt("" + s.charAt(index-2) + s.charAt(index-1));
		this.day = tempDay;
		//System.out.println(this.day);
	}
	
	public int getDay() {
		return day;
	}
	
	public void setHourOfDay(String s){
		int index = s.indexOf(':');
		int tempHour = Integer.parseInt("" + s.charAt(index-2) + s.charAt(index-1));
		this.hourOfDay = tempHour;
		//System.out.println(this.hourOfDay);
	}
	
	public int getHourOfDay() {
		return hourOfDay;
	}
	
	public void setMinute(String s){
		int index = s.indexOf(':');
		int tempMinute = Integer.parseInt("" + s.charAt(index+1) + s.charAt(index+2));
		this.minute = tempMinute;
		//System.out.println(this.minute);
	}
	
	public int getMinute() {
		return minute;
	}

}
